﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Ocmf.Forms;

namespace Ocmf.Types
{
    public class Food : Action
    {
        private float chance;
        public float Chance
        {
            get
            {
                return chance;
            }
            set
            {
                chance = value;
                Text = "Food: Probability " + chance;
            }
        }

        public Food()
        {
            Text = "Food: Probability " + chance;
            SelectedImageKey = ImageKey = "food";
        }

        public override object Clone()
        {
            var clone = base.Clone() as Food;
            clone.Chance = chance;
            return clone;
        }

        public override System.Windows.Forms.Form Editor
        {
            get { return new EditFoodActionForm(this); }
        }

        public override XmlElement ToXml(XmlDocument xmlDocument)
        {
            //create trial xml element
            var foodElement = xmlDocument.CreateElement("Food");
            //create, set and add attribute
            var chanceAttribute = xmlDocument.CreateAttribute("Chance");
            chanceAttribute.InnerText = Chance.ToString();
            foodElement.Attributes.Append(chanceAttribute);
            //return element
            return foodElement;
        }

        public override void FromXml(XmlNode xmlElement)
        {
            Chance = float.Parse(xmlElement.Attributes["Chance"].InnerText);
        }
    }
}
